﻿using System.Collections.Concurrent;
using System.IO.Pipes;

namespace IoTSignalR
{
    //建造者模式(加配置参数)=>工厂模式（建造-实例化）
    public class PipeServerBuilder
    {
        private  string pipeName;
        private  PipeDirection direction;
        private  int maxNumberOfServerInstances;
        private  PipeTransmissionMode transmissionMode;
        private  PipeOptions options;
     
        //建造者就是一层一层的加参数配置
        public PipeServerBuilder WithPipeName(string pipeName)
        {
            this.pipeName = pipeName;
            return this;
        } 
        public PipeServerBuilder WithPipeDirection(PipeDirection direction)
        {
            this.direction = direction;
            return this;
        }
        public PipeServerBuilder WithmaxNumberOfServerInstances(int maxNumberOfServerInstances)
        {
            this.maxNumberOfServerInstances = maxNumberOfServerInstances;
            return this;
        }
        public PipeServerBuilder WithPipeTransmissionMode(PipeTransmissionMode transmissionMode)
        {
            this.transmissionMode = transmissionMode;
            return this;
        }
        public PipeServerBuilder WithPipeOptions(PipeOptions options)
        {
            this.options = options;
            return this;
        }
        //正规=》工厂模式去实例化的
        //建造者采用工厂模式去实例化
        public NamePipeServer Build()
        {
            return PipeServerFactory.CreatePipeServer(pipeName, direction, maxNumberOfServerInstances, transmissionMode, options);
        }
    }
}
